package com.wp.controller.system;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wp.common.CURDUtil;
import com.wp.common.RequestUtil;

@Controller
public class SettingController{
	
	//进入新增学校页面
	@SuppressWarnings("rawtypes")
	@RequestMapping("system/toAddChildMenu.do")
	public ModelAndView toAddChildMenu(HttpServletRequest req,Model model){
		List listMap = new ArrayList<HashMap<String,String>>(); 
		try{
			listMap = CURDUtil.queryList("system.toAddChildMenu", null);
		}catch(Exception e){
			e.printStackTrace();
		}
		model.addAttribute("listMap", listMap);
		return new ModelAndView("system/addChildMenu");
	}
	
	//进入新增学校页面
	@SuppressWarnings({ "rawtypes" })
	@RequestMapping("system/saveChildMenu.do")
	public ModelAndView saveChildMenu(HttpServletRequest req,HttpServletResponse resp){
		Map inparams = RequestUtil.getParams(req);
		
		JSONObject json = new JSONObject();
		try{
			
			resp.setContentType("application/json; charset=utf-8");  
			PrintWriter out = resp.getWriter();
			try{
				CURDUtil.insert("system.saveChildMenu", inparams);
				CURDUtil.update("system.updateParentMenuUrl", inparams);
				json.put("resCode", "0");
			}catch(Exception se){
				json.put("resCode", "1");
			}
			out.write(json.toString());
			if(out!=null){
				out.close();
			}
		}catch(Exception e){
			return null;
		}
		return null;
	}
}
